﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ch04
{
    class Class2
    {
        static void Main(string[] args)
        {

            double n1, n2, result = 0;  //定义变量保存两个操作数及运算结果
            char op = ' ';        //定义变量保存运算符

            string s1 = "", s2 = "";

            Console.Write("请输入一个表达式：");

            char ch;

            while ((ch = (char)Console.Read()) != '\n')
            {
                if (ch == '+' || ch == '-' || ch == '*' || ch == '/')
                {
                    op = ch;
                }
                else
                {
                    if (op == ' ')
                        s1 += ch;
                    else
                        s2 += ch;
                }
            }


            /*
            string str = Console.ReadLine();

            for(int i=0;i<str.Length;i++)
            {
                if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
                {
                    op = str[i];
                }
                else
                {
                    if(op == ' ')
                        s1 += str[i];
                    else
                        s2 += str[i];
                }
            }
            */

            n1 = double.Parse(s1);
            n2 = double.Parse(s2);

            switch (op)
            {
                case '+': result = n1 + n2; break;
                case '-': result = n1 - n2; break;
                case '*': result = n1 * n2; break;
                case '/': result = n1 / n2; break;
                default: Console.WriteLine("运算符有误！"); break;
            }

            Console.WriteLine("{0}{1}{2}={3}", n1, op, n2, result);

        }
    }
}
